import numpy as np



def mAP(pred,gt,degree_thesholds,shift_thesholds):
    num_degree_thes = len(degree_thesholds)
    num_shift_thes = len(shift_thesholds)
    pred_matches = -1 * np.ones([num_degree_thes, num_shift_thes])

    for d, degree_thres in enumerate(degree_thesholds):
        for t, shift_thres in enumerate(shift_thesholds):
            for i in range(len(gt)):
                # Find best matching ground truth box
                # 1. Sort matches by score
                sorted_ixs_by_iou = np.argsort(overlaps[i])[::-1]
                # 2. Remove low scores
                low_score_idx = np.where(overlaps[i, sorted_ixs_by_iou] < score_threshold)[0]
                if low_score_idx.size > 0:
                    sorted_ixs_by_iou = sorted_ixs_by_iou[: low_score_idx[0]]
                # 3. Find the match
                if gt_matches[d, t,] > -1:
                    continue
                # If we reach IoU smaller than the threshold, end the loop
                iou = overlaps[i, j]
                r_error = RT_overlaps[i, j, 0]
                t_error = RT_overlaps[i, j, 1]

                if iou < iou_thres or r_error > degree_thres or t_error > shift_thres:
                    break

                if not pred_class_ids[i] == gt_class_ids[j]:
                    continue

                if iou >= iou_thres or r_error <= degree_thres or t_error <= shift_thres:
                    gt_matches[d, t, s, j] = i
                    pred_matches[d, t, s, i] = j
                    break